﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MDIApplication
{
    public partial class Update : Form
    {
        public Update()
        {
            this.FormBorderStyle = FormBorderStyle.None; 
            InitializeComponent();
        }

        DataView GuestDv = new DataView();
        private void Update_Load(object sender, EventArgs e)
        {
            DataTable bookTab = new DataTable();
            SqlConnection connection = new SqlConnection(@"Data Source=LUCKYPX\LUCKYPX;Initial Catalog=SWENAssignment3;Persist Security Info=True;User ID=sa;Password=imsa");
            connection.Open();
            bookTab.Load(new SqlCommand("Select * from Guest", connection).ExecuteReader());
            dataGridView1.DataSource = GuestDv = bookTab.DefaultView;
            connection.Close();

            //dataGridView1 Propeties
            dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
            dataGridView1.MultiSelect = false;
            dataGridView1.AllowUserToAddRows = false;
            dataGridView1.Rows[0].Selected = false;

            int height = 0;
            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                height += row.Height;
            }
            height += dataGridView1.ColumnHeadersHeight;

            int width = 0;
            foreach (DataGridViewColumn col in dataGridView1.Columns)
            {
                width += col.Width;
            }
            width += dataGridView1.RowHeadersWidth;

            dataGridView1.ClientSize = new Size(width + 2, height + 2);
        }
    }
}
